package com.stoney.utils;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by Stony on 2015/11/23.
 */
public class UrlUtil {


    public static String absUrl(String baseUri, String relUrl) {
        URL base;
        try {
            try {
                base = new URL(baseUri);
            } catch (MalformedURLException e) {
                // the base is unsuitable, but the attribute may be abs on its own, so try that
                URL abs = new URL(relUrl);
                return abs.toExternalForm();
            }
            // workaround: java resolves '//path/file + ?foo' to '//path/?foo', not '//path/file?foo' as desired
            if (relUrl.startsWith("?"))
                relUrl = base.getPath() + relUrl;
            URL abs = new URL(base, relUrl);
            return abs.toExternalForm();
        } catch (MalformedURLException e) {
            return "";
        }
    }
    public static boolean isUrl(String url){
        return url.startsWith("http:") || url.startsWith("https:");
    }


    private final static String[] FOOT_SUFFIX = {".eot",".woff",".ttf",".svg"};

    public static boolean isFont(String src){
        for(String suffix : FOOT_SUFFIX){
            if(src.endsWith(suffix)){
                return true;
            }
            if(src.lastIndexOf(src) > -1){
                return true;
            }
        }
        return false;
    }

    
}
